package com.car.loan.project.cd.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.car.loan.common.exception.loan.LoanParameterException;
import com.car.loan.project.cd.domain.CdCredit;
import com.car.loan.project.cd.domain.CdCreditAlbum;
import com.car.loan.project.cd.mapper.CdCreditAlbumMapper;
import com.car.loan.project.cd.mapper.CdCreditMapper;
import com.car.loan.project.cd.service.ICdCreditAlbumService;
import com.car.loan.project.cd.util.enums.CreditStatus;
import java.util.Collection;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2019-10-28
 */
@Service
public class CdCreditAlbumServiceImpl implements ICdCreditAlbumService {

    @Autowired
    private CdCreditAlbumMapper cdCreditAlbumMapper;

    @Autowired
    private CdCreditMapper cdCreditMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public CdCreditAlbum selectCdCreditAlbumById(Long id) {
        return cdCreditAlbumMapper.selectById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param cdCreditAlbum 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<CdCreditAlbum> selectCdCreditAlbumList(CdCreditAlbum cdCreditAlbum) {
        QueryWrapper<CdCreditAlbum> queryWrapper = new QueryWrapper<>(cdCreditAlbum);
        return cdCreditAlbumMapper.selectList(queryWrapper);
    }


    @Override
    public IPage<CdCreditAlbum> selectPage(IPage<CdCreditAlbum> page,
        QueryWrapper<CdCreditAlbum> queryWrapper) {
        return cdCreditAlbumMapper.selectPage(page, queryWrapper);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param cdCreditAlbum 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertCdCreditAlbum(CdCreditAlbum cdCreditAlbum) {

        return cdCreditAlbumMapper.insert(cdCreditAlbum);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param cdCreditAlbum 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateCdCreditAlbum(CdCreditAlbum cdCreditAlbum) {

        return cdCreditAlbumMapper.updateById(cdCreditAlbum);
    }

    /**
     * 删除【请填写功能名称】对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCdCreditAlbumByIds(Collection<Long> ids) {
        return cdCreditAlbumMapper.deleteBatchIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteCdCreditAlbumById(Long id) {
        CdCreditAlbum cdCreditAlbum = cdCreditAlbumMapper.selectById(id);
        if (null == cdCreditAlbum) {
            return 1;
        }
        CdCredit cdCredit = cdCreditMapper.selectById(cdCreditAlbum.getCreditId());
        if (cdCredit.getStatus() != CreditStatus.INIT.status && cdCredit.getStatus() != CreditStatus.REVOKE.status) {
            throw new LoanParameterException("当前状态不可删除");
        }
        return cdCreditAlbumMapper.deleteById(id);
    }
}
